package com.jms.publisher;

import java.util.Date;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.Session;

import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

public class PublisherServiceImpl implements PublisherService{

	private JmsTemplate jmsTemplate;
	
	private Destination destination;
	
	public JmsTemplate getJmsTemplate() {
		return jmsTemplate;
	}

	public void setJmsTemplate(JmsTemplate jmsTemplate) {
		this.jmsTemplate = jmsTemplate;
	}

	public Destination getDestination() {
		return destination;
	}

	public void setDestination(Destination destination) {
		this.destination = destination;
	}

	@Override
	public void send() {
		
		MessageCreator messageCreator = new MessageCreator(){

			@Override
			public Message createMessage(Session session) throws JMSException {
				MapMessage msg = session.createMapMessage();
				msg.setString("time", new Date().toString());
				return msg;
			}};
		System.out.println("发送一条消息");
		this.jmsTemplate.send(destination, messageCreator);
	}

}
